package com.yunsom.testdemo.design.chain_of_responsibility;

/**
 * @author Xbao
 * @description 责任链模式
 * @date 2022/6/22 9:49
 */
public class TestChainResponsibility {

  public static void main(String[] args) {

    AbstractLogger loggerChain = getChainOfLoggers();

//    loggerChain.logMessage(AbstractLogger.INFO, "This is an info information");
//    loggerChain.logMessage(AbstractLogger.DEBUG, "This is a debug information");
    loggerChain.logMessage(AbstractLogger.ERROR, "This is an error information");

  }

  private static AbstractLogger getChainOfLoggers(){
    AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
    AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
    AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);

    errorLogger.setNextLogger(fileLogger);
    fileLogger.setNextLogger(consoleLogger);

    return errorLogger;
  }
}
